home *** CD-ROM | disk | FTP | other *** search
- ; $Id: xdice.pro,v 1.1 1996/10/01 22:03:16 doug Exp $
-
- ; Copyright (c) 1993, Research Systems, Inc. All rights reserved.
- ; Unauthorized reproduction prohibited.
- ;+
- ; NAME:
- ; XDICE
- ;
- ; PURPOSE:
- ; The primary purpose of this routine is to serve as an example for
- ; the Widgets chapter of the IDL User's Guide. It uses the CW_DICE
- ; compound widget (also written as an example) to present a pair
- ; of dice.
- ;
- ; CATEGORY:
- ; Widgets
- ;
- ; CALLING SEQUENCE:
- ; XDICE
- ;
- ; INPUTS:
- ; No explicit inputs.
- ;
- ; KEYWORD PARAMETERS:
- ; GROUP - Group leader, as passed to XMANAGER.
- ;
- ; OUTPUTS:
- ; None.
- ;
- ; PROCEDURE:
- ; Two dice are presented, along with "Done" and "Roll" buttons.
- ; Pressing either dice rolls that dice. pressing the Roll
- ; button rolls both dice.
- ;
- ; A label widget at the bottom displays the current dice values.
- ; Press "Done" to kill the application.
- ;
- ; MODIFICATION HISTORY:
- ; 24 October 1993, AB, RSI
- ;-
-
- pro xdice_event, ev
-
- ; Recover the state
- WIDGET_CONTROL, ev.top, GET_UVALUE=state, /NO_COPY
-
- if (ev.id eq state.bgroup) then begin
- if (ev.value eq 0) then begin
- WIDGET_CONTROL, /DESTROY, ev.top
- return
- endif else begin
- WIDGET_CONTROL, state.d1, SET_VALUE=-1
- WIDGET_CONTROL, state.d2, SET_VALUE=-1
- endelse
- endif
-
- ; Update Label
- WIDGET_CONTROL, state.d1, get_value=d1v
- WIDGET_CONTROL, state.d2, get_value=d2v
- WIDGET_CONTROL, state.label, $
- set_value=string(format='("Current Value: ", I1, ", ", I1)', d1v, d2v)
-
- ; Restore the state
- WIDGET_CONTROL, ev.top, SET_UVALUE=state, /NO_COPY
-
- end
-
-
- pro xdice, GROUP=group
-
- base = widget_base(/COLUMN, title='Pair O'' Dice')
- bgroup=cw_bgroup(base, ['Done', 'Roll'], /ROW, SPACE=50)
- dice=widget_base(base, /ROW, XPAD=20)
- d1 = cw_dice(dice)
- d2 = cw_dice(dice)
- WIDGET_CONTROL, d1, get_value=d1v
- WIDGET_CONTROL, d2, get_value=d2v
- label=WIDGET_LABEL(base, $
- value=string(format='("Current Value: ", I1, ", ", I1)', d1v, d2v))
-
- ; Keep useful information in UVALUE of top-level base.
- state = { bgroup:bgroup, d1:d1, d2:d2, label:label }
- ; Use the UVALUE of the top-level base to hold both Dice IDs.
- widget_control, base, set_uvalue=state, /NO_COPY, /REAL
-
- XMANAGER,'XDICE', base, GROUP=group
- end
-
-